/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.dw.hiveapi.hiveapitest;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author lidejia
 */
public class HiveSession {

    private volatile int processPercentage = 0;
    private Future<HiveQueryResult> future = null;
    private HiveJobExecutor executor = HiveJobExecutor.getInstance();
    private Long sessionID;

    public HiveSession(String dbName, String sql, Long sessionID) {
        this.sessionID = sessionID;
        HiveJob job = new HiveJob(this, dbName, sql);
        future = executor.execute(job);
    }

    public Long getSessionID() {
        return sessionID;
    }

    public HiveQueryResult getResult() {
        HiveQueryResult result = null;
        try {
            result = future.get();
        } catch (InterruptedException ex) {
            Logger.getLogger(HiveSession.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ExecutionException ex) {
            Logger.getLogger(HiveSession.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    public int getProcessPercentage() {
        return processPercentage;
    }

    public void setProcessPercentage(int processPercentage) {
        this.processPercentage = processPercentage;
    }
}
